jsBridge = {
    ...(HarmonyBridge || {}),
    registerHandle: (handleName, callbackName) => {
        console.log('HarmonyBridge registerHandle handleName=' + handleName, " callbackName =" + callbackName)
        switch (handleName) {
            case 'getUIConfig()':
                getUIConfig(callbackName, (result) => {
                    console.log('HarmonyBridge getConfigUI', 'result:' + result)
                })
                break;
            default:
                break;
        }

    },
};

function callNativeHandle(name) {
    console.log('HarmonyBridge callNativeHandle', 'result:' + name)
    switch (name) {
        case 'getVersion':
            getVersion(name, (result) => {
                console.log('HarmonyBridge getVersion  name:' + name, 'result:' + result)
            })
            break;
        default:
            break;
    }
}

function nativeHandle(name, params, callback) {
    console.log('HarmonyBridge callNative name=' + name, 'params=' + JSON.stringify(params))
    let javaScriptHandle = jsBridge.javaScriptHandle.bind(HarmonyBridge);
    javaScriptHandle(name, JSON.stringify(params), callback);
}

function getVersion(name, callback) {
    console.log('HarmonyBridge getVersion ')
    let params = { msg: 'ok', data: { version: '1.0.0' }, code: 0 }
    nativeHandle(name, params, (result) => {
        console.log('HarmonyBridge  getVersion', 'result:' + result)
        callback(result);
    }
    )
}


//TODO:native 无法通过 runJavaScriptExt 获取返回值,需要到指定的handleName 方法中获取到返回值
function getUIConfig(callbackName, callback) {
    console.log('HarmonyBridge getConfigUI ', 'callbackName:' + callbackName)
    let params = { msg: 'ok', data: { back: true, download: false }, code: 0 }
    nativeHandle(callbackName, params, (result) => {
        console.log('HarmonyBridge  getConfigUI', 'result:' + result)
        callback(result);
    })
}




